class Goods{
    sellIn:number;
    quality:number;
    name:string;
    constructor(name:string,sellIn:number,quality:number){
        this.sellIn=sellIn;
        this.quality =quality;
        this.name =name;
    }
    
    updateByDay(){
        if(this.name=='cheese'){
            if (this.sellIn > 0) {
                // 没过保
                this.quality = this.quality + 1;
            } else {
                // 已过保
                this.quality = this.quality + 2;
            }
        }else if(this.name=='normal'){
            if (this.sellIn <= 0) {
                this.quality = this.quality - 2;
            } else {
                this.quality = this.quality - 1;
            }
      
        }else if(this.name=='ticket'){
            console.log(this.sellIn ,   this.quality)
            // 距离演出前10天之前，门票价值每天上升1点
            if (this.sellIn > 10)   this.quality = this.quality + 1;
            // 距离演出5~10天时间范围内，门票价值每天上升2点
            if(this.sellIn <= 10 && this.sellIn > 5)  this.quality = this.quality + 2;
            // 距离演出5天以内，门票价值每天上升3点
            if(this.sellIn <= 5 && this.sellIn >=1) this.quality = this.quality + 3;
            // 到达演出当天，门票价值为0
            if(this.sellIn <= 0) this.quality = 0;
        }
        // 商品的价值永远不会小于0
        if( this.quality < 0)  this.quality = 0;
        // 商品的价值永远不会大于50
        if( this.quality > 50)  this.quality = 50;
        // 日常更新，保质期-1
        this.sellIn = this.sellIn - 1;
    }
    updateDouble(){
        this.sellIn = this.sellIn-1;
        this.quality = this.quality-2;
    }
    getSellIn(){
        return this.sellIn;
    }
    getQuality(){
        return this.quality;
    }
}
let quality = 20;
    let sellIn = 15;
    const goods = new Goods('ticket',sellIn,quality);
    goods.updateByDay();
    let updatedQuality = goods.getQuality();
    let updatedSellIn = goods.getSellIn();
    console.log(updatedQuality,updatedSellIn)
export default Goods